﻿using System;

class ArrayMaxSum
{
    static void Main()
    {
        Console.Write("How long will be your array : ");
        int n = int.Parse(Console.ReadLine());
        int[] Array = new int[n];
        Console.WriteLine("Insert {0} integer", n);
        for (int i = 0; i < Array.Length; i++)
        {
            Console.Write("{0}:", i + 1);
            Array[i] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine("Sequence must be smaller then the array (array = {0})" , n);
        Console.Write("How long will be sequence : ");
        int k = int.Parse(Console.ReadLine());
        int sum = 0;
        int MaxSum = 0;
        int StartingElement = 0;
        for (int i = 0; i < Array.Length-k; i++)
        {
            for (int j = 0+i; j < k+i; j++)
            {
                sum += Array[j];
            }
            if (MaxSum < sum)
            {
                MaxSum = sum;
                StartingElement = i;
            }
            sum = 0;
        }
        Console.WriteLine("Maximal sum in sequence of {0} elements is {1}" , k , MaxSum);
        Console.Write("The elements giving maximal sum are ");
        for (int r = StartingElement; r < StartingElement+k; r++)
        {
            Console.Write("{0} " , Array[r]); 
        }
        Console.WriteLine();
    }
}
